home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / System / XFD / Developer / Sources / ASM / Damage.a < prev    next >
Encoding:
Text File  |  2001-09-16  |  3.5 KB  |  169 lines

  1. **********************************************************
  2. **       XFD external decruncher for Damage files       **
  3. **       Written and © 2000 by Codetapper/Action!       **
  4. **              Improved by Dirk Stoecker!              **
  5. **                                                      **
  6. **      This decrunches files in the game Damage.       **
  7. **                                                      **
  8. **          Contact me: codetapper@hotmail.com          **
  9. **      Visit the Action HQ: http://zap.to/action/      **
  10. **********************************************************
  11.  
  12.         OUTPUT    "LIBS:xfd/Damage"
  13.  
  14. DamageMinLen    equ    12        ;Min. file length for header and data
  15.  
  16.         SECTION    Damage,CODE
  17.  
  18.         INCDIR    "sc:Include/"    ;change this as you need it
  19.         INCLUDE    "libraries/xfdmaster.i"
  20.  
  21. ; xfdForeman structure MUST be first thing in all external decrunchers
  22.  
  23. Foreman        moveq    #-1,d0        ;security
  24.         rts
  25.         dc.l    XFDF_ID        ;id
  26.         dc.w    1        ;version
  27.         dc.w    0
  28.         dc.l    0,0        ;private
  29.         dc.l    S_Damage    ;first slave
  30.  
  31.         dc.b    "$VER: Damage 1.1 (14.10.00) Codetapper/Action!",13,10,0
  32. N_Damage    dc.b    'Damage Cruncher',0
  33.         cnop    0,4
  34.  
  35. S_Damage    dc.l    0        ;next slave
  36.         dc.w    2        ;version
  37.         dc.w    39        ;master version
  38.         dc.l    N_Damage    ;name
  39.         dc.w    XFDPFF_DATA|XFDPFF_RECOGLEN|XFDPFF_USERTARGET
  40.         dc.w    0
  41.         dc.l    RB_Damage    ;recog buffer
  42.         dc.l    DB_Damage    ;decrunch buffer
  43.         dc.l    0        ;recog segment
  44.         dc.l    0        ;decrunch segment
  45.         dc.w    0,0        ;slave/replace id
  46.         dc.l    DamageMinLen    ;min. file length for header and data
  47.  
  48. RB_Damage    moveq    #0,d0
  49.         cmp.l    #'DMG!',(a0)
  50.         bne.s    .Exit
  51.         move.l    4(a0),d1
  52.         and.l    #$ffffff,d1
  53.         cmp.l    #DamageMinLen,d1
  54.         blt.b    .Exit
  55.         move.l    d1,xfdrr_FinalTargetLen(a1)
  56.         move.l    d1,xfdrr_MinTargetLen(a1)
  57.         moveq    #1,d0
  58. .Exit        rts
  59.  
  60. DB_Damage    movem.l    d2-d7/a2-a6,-(a7)
  61.         move.l    xfdbi_UserTargetBuf(a0),a1
  62.         move.l    xfdbi_SourceBuffer(a0),a0
  63.  
  64. ;---------------------------------------------------------
  65. ; Damage decruncher (ripped from Damage)
  66. ;
  67. ; Inputs:
  68. ; a0 = Source data
  69. ; a1 = Destination address
  70. ;
  71. ; Returns:
  72. ; None
  73. ;---------------------------------------------------------
  74.         move.w    #7,d2
  75.         move.l    (a0)+,d0
  76.         move.l    (a0)+,d0
  77.         move.l    d0,d1
  78.         swap    d1
  79.         lsr.l    #8,d1
  80.         moveq    #1,d4
  81.         lsl.l    d1,d4
  82.         subq.l    #1,d4
  83.         movea.l    a1,a4
  84.         movea.l    a1,a3
  85.         andi.l    #$FFFFFF,d0
  86.         adda.l    d0,a3
  87. .mainloop    cmpa.l    a3,a1
  88.         bge.b    .end
  89.         moveq    #1,d1
  90.         bsr.b    DMGgetbits
  91.         tst.b    d0
  92.         bne.b    .parse
  93.         moveq    #8,d1
  94.         bsr.b    DMGgetbits
  95.         move.b    d0,(a1)+
  96.         bra.b    .mainloop
  97.  
  98. .end        moveq    #1,d0
  99.         movem.l    (a7)+,d2-d7/a2-a6
  100.         rts
  101.  
  102. .parse        move.l    a1,d6
  103.         sub.l    a4,d6
  104.         cmp.l    d4,d6
  105.         ble.b    .bigbuffer
  106.         move.w    d4,d6
  107. .bigbuffer    lea    (DMGTable,pc),a6
  108.         moveq    #13,d5
  109. .parsetable    cmp.w    (a6)+,d6
  110.         bge.b    .leavetable
  111.         dbra    d5,.parsetable
  112.         moveq    #2,d5
  113. .leavetable    moveq    #8,d1
  114.         bsr.b    DMGgetbits
  115.         move.w    d0,d6
  116.         beq.b    .copystored
  117.         move.w    d5,d1
  118.         bsr.b    DMGgetbits
  119.         neg.w    d0
  120.         andi.w    #$FF,d6
  121.         addq.w    #1,d6
  122. .copybackloop    move.b    (a1,d0.w),(a1)+
  123.         dbra    d6,.copybackloop
  124.         bra.b    .mainloop
  125.  
  126. .copystored    moveq    #12,d1
  127.         bsr.b    DMGgetbits
  128.         move.w    d0,d6
  129.         subq.w    #1,d6
  130. .copystoredloop    moveq    #8,d1
  131.         bsr.b    DMGgetbits
  132.         move.b    d0,(a1)+
  133.         dbra    d6,.copystoredloop
  134.         bra.b    .mainloop
  135.  
  136. DMGgetbits    moveq    #0,d0
  137.         move.w    d1,d3
  138.         subq.w    #1,d1
  139. .loop        lsr.w    #1,d0
  140.         btst    d2,(a0)
  141.         beq.b    .nobit
  142.         bset    #15,d0
  143. .nobit        subq.w    #1,d2
  144.         bpl.b    .nonewbyte
  145.         moveq    #7,d2
  146.         addq.l    #1,a0
  147. .nonewbyte    dbra    d1,.loop
  148.         moveq    #$10,d1
  149.         sub.w    d3,d1
  150.         lsr.w    d1,d0
  151.         rts
  152.  
  153. DMGTable    DC.W    $1000
  154.         DC.W    $800
  155.         DC.W    $400
  156.         DC.W    $200
  157.         DC.W    $100
  158.         DC.W    $80
  159.         DC.W    $40
  160.         DC.W    $20
  161.         DC.W    $10
  162.         DC.W    8
  163.         DC.W    4
  164.         DC.W    2
  165.         DC.W    1
  166.  
  167.         DC.W    0            ;Safety
  168.         END
  169.